<template>
    <div>
        <van-cell-group style="margin-top: 10px;">
            <van-field v-model="loginPwd" type="password" placeholder="请输入原登录密码" />
            <van-field v-model="newLoginPwd"  type="password" placeholder="请输入新登录密码" />
        </van-cell-group>
        <div class="tips">
            <router-link to="/forget" style="color: #0079f3">忘记登录密码？</router-link>
        </div>

        <div class="btn"><van-button type="primary" @click="submit">确&nbsp;认</van-button></div>
    </div>
</template>

<script>
import reg from './../../lib/pwdReg';
import md5 from 'js-md5';
export default {
    name: 'editLoginPassword',
    data() {
        return {
            newLoginPwd: '',
            loginPwd: ''
        }
    },
    methods: {
        submit() {
            if (this.loginPwd === '') {
                this.$toast('请输入原登录密码');
                return;
            }

            if (!reg.reg.test(this.loginPwd)) {
                this.$toast(reg.text);
                return;
            }
            if (this.newLoginPwd === '') {
                this.$toast('请输入新登录密码');
                return;
            }

             if (!reg.reg.test(this.newLoginPwd)) {
                this.$toast(reg.text);
                return;
            }

            this.$http.post('/user/user/front/modifyLoginPwd', {
                loginPwd: md5(this.loginPwd),
                newLoginPwd: md5(this.newLoginPwd)
            }).then(res => {
                if (res.status === 0) {
                    this.$toast.success('修改成功');
                } else {
                    this.$toast.fail(res.message);
                }
            })
        }
    }
}
</script>

<style scoped lang="scss">
.tips {
    padding: 5px 15px;
}

.btn {
    width: 100%;
    padding: 15px;
    /deep/ .van-button {
        width: 100%;
    }
}
</style>
